(function(){

$(function(){
	
let app = new Vue({
	el: "#app",
	data(){
		return {
			Action: "create",
			PlayerCount: 8,
			Policy: null
		}
	},
	computed: {
		Board(){
			return GameBoard[this.PlayerCount];
		},
		PolicyZhongPlayerCount(){
			return this.Board.Good - (this.Policy.NeedPai?1:0) - 1;
		},
		PolicyZhuaPlayerCount(){
			return this.Board.Bad - (this.Policy.NeedNa?1:0) - (this.Policy.NeedMo?1:0) - (this.Policy.NeedAo?1:0) - 1;
		}
	},
	watch: {
		PlayerCount: {
			immediate: true,
			handler(val){
				this.Policy = Object.assign({
					Turn: 0
				}, GameBoard[val].Default);
			}
		}
	},
	methods: {
		Create(){
			let count = this.PlayerCount;
			let turn = this.Policy.Turn;
			
			let mask = 0;
			let bad = 1;
			if(this.Policy.NeedPai){
				mask |= 0x01;
			}
			if(this.Policy.NeedNa){
				mask |= 0x02;
				bad++;
			}
			if(this.Policy.NeedMo){
				mask |= 0x04;
				bad++;
			}
			if(this.Policy.NeedAo){
				mask |= 0x08;
				bad++;
			}
			if(this.Policy.BadShow){
				mask |= 0x10;
			}
			
			if(bad > this.Board.Bad){
				this.$message({
					showClose: true,
					type: "error",
					message: "坏人过多"
				});
				return;
			}
			
			let number = ~~(Math.random() * 10000);
			let room = 
				MaskValue[mask] + 
				MaskValue[(turn * 10 + (count - 5))] + 
				pad(number)
			;
			
			location.href = `after-create.html?room=${room}`;
		}
	}
});

function pad(value){
	if(value < 10){
		return "000" + value;
	}
	if(value < 100){
		return "00" + value;
	}
	if(value < 1000){
		return "0" + value;
	}
	return value;
}

});

})();